// DlgBadPixelFile.cpp : implementation file
//

#include "stdafx.h"
#include "PanelImage.h"
#include "DlgBadPixelFile.h"


// DlgBadPixelFile dialog

IMPLEMENT_DYNAMIC(DlgBadPixelFile, CDialog)

DlgBadPixelFile::DlgBadPixelFile(CWnd* pParent /*=NULL*/)
	: CDialog(DlgBadPixelFile::IDD, pParent)
{

}

DlgBadPixelFile::~DlgBadPixelFile()
{
}

void DlgBadPixelFile::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_BADPIXELFILE, m_ComBoxPixelFile);
}


BEGIN_MESSAGE_MAP(DlgBadPixelFile, CDialog)
	ON_BN_CLICKED(IDC_CHECK_SELECTBADPIXELFILE, &DlgBadPixelFile::OnBnClickedCheckSelectbadpixelfile)
	ON_BN_CLICKED(IDOK, &DlgBadPixelFile::OnBnClickedOk)
END_MESSAGE_MAP()


BOOL DlgBadPixelFile::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here
	theApp.SetDialogString(this, IDD);

	TCHAR szFileDir[MAX_PATH];

	Safesprintf(m_szFileDir,_T("%s\\revise"),theApp.GetAppPath() );
	Safesprintf(szFileDir,_T("%s\\*.pix"),m_szFileDir );

	WIN32_FIND_DATA   filedata; 
	HANDLE            filehandle; 

	filehandle = FindFirstFile( szFileDir,&filedata); 

	if(filehandle!=INVALID_HANDLE_VALUE) 
	{ 
		do 
		{ 
			if( FILE_ATTRIBUTE_DIRECTORY != filedata.dwFileAttributes )
			{
				if( Safestrlen( filedata.cFileName ) > 4 ) 
				{ 
					m_ComBoxPixelFile.AddString( filedata.cFileName );

					if( Safestrcmp(CMainFrame::m_SysConfigParam.szBadPixelFile,filedata.cFileName) )
					{
						m_ComBoxPixelFile.SetCurSel( m_ComBoxPixelFile.GetCount() - 1 );

						( (CButton*)GetDlgItem(IDC_COMBO_BADPIXELFILE) )->SetCheck( 1 );
					}
				} 
			}

		}while( FindNextFile(filehandle,&filedata) ); 

		FindClose(filehandle); 
	} 

	OnBnClickedCheckSelectbadpixelfile();


	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

// DlgBadPixelFile message handlers

void DlgBadPixelFile::OnBnClickedCheckSelectbadpixelfile()
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_COMBO_BADPIXELFILE)->EnableWindow( IsDlgButtonChecked(IDC_CHECK_SELECTBADPIXELFILE) ? TRUE:FALSE );	
}

void DlgBadPixelFile::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	Safesprintf( CMainFrame::m_SysConfigParam.szBadPixelFile,_T("") ); 

	if( IsDlgButtonChecked(IDC_CHECK_SELECTBADPIXELFILE) )
	{
		TCHAR sFileName[100] = {0};
		int nSel = m_ComBoxPixelFile.GetCurSel();
		if( nSel >= 0 )
		{
			m_ComBoxPixelFile.GetLBText( nSel,sFileName );
			if( Safestrlen(sFileName) > 0 )
			{
				Safesprintf( CMainFrame::m_SysConfigParam.szBadPixelFile,_T("%s"),sFileName ); 
			} 
		}
	}

	CMainFrame::WriteSysConfigParam();

	MyMainFrame->m_pDynamicView->LoadBadPixelFile();

	OnOK();
}


